package dice.sinanya.db.custom;

import dice.sinanya.db.tools.DbUtil;
import dice.sinanya.entity.EntityCustomSearch;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

/**
 * @author SitaNya
 * 日期: 2019-06-15
 * 电子邮箱: sitanya@qq.com
 * 维护群(QQ): 162279609
 * 有任何问题欢迎咨询
 * 类说明: 录入KP主群类
 */
public class InsertCustomSearch {
    private static final Logger log = LogManager.getLogger(InsertCustomSearch.class.getName());

    public void insertCustom(EntityCustomSearch entityCustomSearch) {
        int num = 0;
        try (Connection conn = DbUtil.getConnection()) {
            String sql = "REPLACE INTO coc.customSearch(inputDate,`key`, messages, authorId, authorNick,enable) VALUE(?,?,?,?,?,?)";
            try (PreparedStatement ps = conn.prepareStatement(sql)) {
                ps.setTimestamp(1, entityCustomSearch.getInputDate());
                ps.setString(2, entityCustomSearch.getKey());
                ps.setString(3, entityCustomSearch.getMessages());
                ps.setString(4, entityCustomSearch.getAuthorId());
                ps.setString(5, entityCustomSearch.getAuthorNick());
                ps.setInt(6, 0);
                ps.executeUpdate();
            }
        } catch (SQLException e) {
            log.error(e.getMessage(), e);
        }
    }
}